<?php
namespace app\admin\controller;
use app\admin\model\Config as ConfigModel;
use app\admin\model\WebSet as WebSetModel;

/**
 * 站点配置
 */
class Setting extends Controller
{
    /**
     * 平台设置
     */
    public function open()
    {
        $model = ConfigModel::detail();
        if ($this->request->isAjax()) {
			//测试判断
			if($this->admin['user']['config_id']==0){
				return $this->renderError('测试用户不可操作');
			}
            if ($model->edit($this->postData('config'))){
				return $this->renderSuccess('更新成功');
			}
            return $this->renderError('更新失败');
        }
        return $this->fetch('open', compact('model'));
    }
	
	/**
     * 站点设置
     */
    public function web()
    {
        return $this->updateEvent('web');
    }
	
	/**
     * 注册设置
     */
    public function register()
    {
        return $this->updateEvent('register');
    }
	
	/**
     * 配送接口
     */
    public function delivery()
    {
        return $this->updateEvent('delivery');
    }
	
	/**
     * 收款设置
     */
    public function pay()
    {
        return $this->updateEvent('pay');
    }
	
	/**
     * 商户手机端设置
     */
    public function wxapp()
    {
        return $this->updateEvent('wxapp');
    }

    /**
     * 更新设置事件
     */
    private function updateEvent($key)
    {
        if (!$this->request->isAjax()) {
            $values = WebSetModel::getItem($key);
            return $this->fetch($key, compact('values'));
        }
		//测试判断
		if($this->admin['user']['config_id']==0){
			return $this->renderError('测试用户不可操作');
		}
        $model = new WebSetModel;
        if ($model->edit($key,$this->postData($key))) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError('更新失败');
    }

}
